package com.zs.hydrant.service.impl;

import com.zs.hydrant.entity.FireHydrant;
import com.zs.hydrant.mapper.FireHydrantMapper;
import com.zs.hydrant.service.FireHydrantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class FireHydrantServiceImpl implements FireHydrantService {
    @Autowired
    private FireHydrantMapper hydrantMapper;

    @Override
    public FireHydrant getNearestHydrant(BigDecimal userLat, BigDecimal userLon) {
        return hydrantMapper.findNearestHydrant(userLat, userLon);
    }

    @Override
    public int addHydrant(FireHydrant hydrant) {
        // 设置默认值
        if (hydrant.getStatus() == null) {
            hydrant.setStatus(0); // 0表示正常
        }
        return hydrantMapper.addFireHydrant(hydrant);
    }

    @Override
    public int updateHydrantStatus(Integer id, Integer status) {
        // 调用mapper层更新消防栓状态
        return hydrantMapper.updateHydrantStatus(id, status);
    }

    @Override
    public List<FireHydrant> getAllHydrants() {
        return hydrantMapper.getAllFireHydrants();
    }
    
    @Override
    public void removeById(Integer id) {
        hydrantMapper.removeById(id);
    }
    
    @Override
    public void updateById(FireHydrant hydrant) {
        hydrantMapper.updateById(hydrant);
    }
}